package dk.au.cs.bdsi.sms.activities;

import dk.au.cs.bdsi.core.representation.Identifier;
import dk.au.cs.bdsi.core.representation.ServiceUri;
import dk.au.cs.bdsi.sms.domain.Sms;
import dk.au.cs.bdsi.sms.domain.SmsStatus;
import dk.au.cs.bdsi.sms.repositories.SmsRepository;
import dk.au.cs.bdsi.sms.representation.SmsRepresentation;

/**
 * Creates a new {@link Sms} by storing the received Sms in the {@link SmsRepository}
 * and thus assigning it a new unique {@link Identifier}.
 */
public class CreateSmsActivity {
	public SmsRepresentation create(Sms sms, ServiceUri requestUri) {
		/*
		 * Ignore any status given, newly created sms' always has a
		 * 'Pending' status, until it has been processed by the 
		 * sms sending backend.
		 */
		sms.setStatus(SmsStatus.Pending);
		
		// TOD Perform validity check on user-supplied sms
		
		Identifier id = SmsRepository.current().store(sms);
		ServiceUri smsUri = new ServiceUri(requestUri.getBaseUri()+ "/sms/" + id);
		return SmsRepresentation.createResponseRepresentation(sms, smsUri);
	}
}
